﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Homework_1
{
    class Program
    {
        static void Main(string[] args)
        {
            /*Homework 1 - User Interaction with command promt;
              Store data on "strings" for text, or "char" for a single character or "int" for numeric values
              You will notice that i put notes on most of the code as i see fit, most people add notes before a command to explain what it does
              Some other add the note in the same line were the command is written at the end on the line.*/
            string uName, uAgeVerify, uSubmit; //Activating strings to add value later in the code
            string uChanges = "False";
            string uGender = " ";
            int uAge = 0; //This is the variable that will hold the value for the age
            char tok = ' '; //this 'char' named 'tok' holds the value for a 'space' that I need
            //first line of text to be displayed in the promt as a title and description of the program
            Console.WriteLine("HOMEWORK 1\nUser interaction with the cmd prompt\nCreate strings and add values to be used latter in the code.\n");
            //The next text "Name:" is a way to name a segment were we can redirect the program to come back, more on that latter
            Name:
            //More text to be displayed, this time asking for the user to type his first and last name
            Console.WriteLine("Please provide your Name, First and Last Only, ex:\"John Doe\"");
            //The next line is where we set a value to the string "uName" to whatever you type on the command prompt
            uName = Console.ReadLine();
            //The next if makes sure that you have tiped at least 2 words, checking for spaces on the provided value.
            if (!uName.Contains(tok))
            {
                Console.WriteLine("\nInvalid Name");
                goto Name;
            }
            /*The next line is a way to divide by spaces any words typed for the name and they will be assigned to a "unique" string each word
              in this code the new string will be vName and each word will have a number ex: vName[0] vName[1] all the words typed before for the Name will ve divided*/
            string[] vName = uName.Split(tok);
            //this next IF 'statement' or command is a WEAK protection to make sure that the first and last name are writen and has more than 3 Letters on them
            if (vName[0].Length < 3 || vName[1].Length < 3)
            {
                /*The program has rejected the name you have wirtten because it has a Name OR a Last name of less than 3 letters and will send the program back to were you write your name
                  Remember how we put Name: on top as the name of that segment, using the command 'goto Name' the program is sent back to that location */
                Console.WriteLine("\nInvalid Name");
                goto Name;
            }
            if (uChanges == "True") goto Done;
            Console.WriteLine("\nThank You {0}", uName);
            //Same as in "Name:" A segment were we can redirect the program to come back to this point, this segment is called "Age"
            Age:
            Console.WriteLine("\nPlease provide your Age");
            /*This next "while" statement will make sure a "correct" value for Age is given
              if letters or decimals or big numbers are given this while will keep running untill an aceptable Age is set
              in other words you are telling the program "while the answer is not aceptable keep asking for it" */
            while (!int.TryParse(Console.ReadLine(), out uAge))
                Console.WriteLine("\nYou have provided an invalid Age, please provide your age as Years with no decimals.");
            /*IF a valid number was set in the variable but it was less than 18 or greater than 75,
              this next IF statement will ask if the given number is the right Age.
              the lines '||' means "or" inside an 'if' or 'while'*/
            if (uAge < 18 || uAge > 75)
            {
                //Same as in Age: or Name: you can have as many segments as you need, remember these are only to use the 'goto Segment' command
                Age2:
                Console.WriteLine("\n{0} Is your Age really {1}? Y or N?", vName[0], uAge);
                uAgeVerify = Console.ReadLine();
                //now the program will make sure that the valid answer is only "Y,y,N or n"
                if (uAgeVerify == "Y" || uAgeVerify == "y")
                {
                    //This next line is set to "True" when you have reached the end of the program and decided to change your age, it will send you to the end of the program so the gender is not asked again
                    if (uChanges == "True") goto Done;
                    Console.WriteLine("\nOk, Thank You {0}, we will continue now.", vName[0]);
                }
                else if (uAgeVerify == "N" || uAgeVerify == "n")
                {
                    //OR if the answer was N or n for NO, the program will send you back to where the Age was first asked
                    goto Age;
                }
                //Finally there was no Y o N answer given, question will be asked Again by sending the program back to "Age2"
                else goto Age2;
            }
            //This next if is set true at the end of the program, in case you edit your Age you will not be asked your gender again and will skip to the end
            if (uChanges == "True") goto Done;
            //Gender segment, same as in Age:
            Gender:
            Console.WriteLine("\n{0}, please provide your Gender, \"M\" or \"Male\",\"F\" or \"Female\"", vName[0]);
            //uGender will hold the value for the gender
            uGender = Console.ReadLine();
            //this next if will make sure the only valid answers are "M,m,Male,male,f,F,female,Female"
            if (uGender == "M" || uGender == "m" || uGender == "Male" || uGender == "male")
            {
                uGender = "Male";
            }
            else if (uGender == "F" || uGender == "f" || uGender == "Female" || uGender == "female")
            {
                uGender = "Female";
            }
            else
            {
                //there was no valid answer, send the program back to get a valid answer
                Console.WriteLine("\nInvalid answer!");
                goto Gender;
            }
            //"Done" segment, if you do any changes you will be send here after every change so the program doesnt ask you everything again
            Done:
            uChanges = "True";
            Console.WriteLine("\nThank you {0} for the provided information.", vName[0]);
            Console.WriteLine("If you would like to change your Name: {0} type \"Name\"\nTo change your Age: {1} type \"Age\"\nTo change your Gender: {2} \"Gender\"\nIf you dont want to make any changes just type \"Done\".", uName, uAge, uGender);
            //"uSubmit" holds the value if you want to change or finish the program
            Done2:
            uSubmit = Console.ReadLine();
            //This if will check the value given the previous string and validate it to send you to the right places to make changes or if "Done" is written the program will continue
            if (uSubmit == "Name" || uSubmit == "name")
            {
                goto Name;
            }
            else if (uSubmit == "Age" || uSubmit == "age")
            {
                goto Age;
            }
            else if (uSubmit == "Gender" || uSubmit == "gender")
            {
                goto Gender;
            }
            else if (uSubmit == "Done" || uSubmit == "done")
            {
                Console.WriteLine("\nThe data you have provided is as follows:\nName: {0}\nAge: {1}\nGender: {2}\n", uName, uAge, uGender);
            }
            else
            {
                //there was no valud input/answer so the program will send you back to provide an anwer and revalidate it.
                Console.WriteLine("\nPlease provide a valid answer.\nIf you would like to change your Name: {0} type \"Name\"\nTo change your Age: {1} type \"Age\"\nTo change your Gender: {2} \"Gender\"\nIf you dont want to make any changes just type \"Done\".", uName, uAge, uGender);
                goto Done2;
            }
            Console.WriteLine("\nEND OF THE PROGRAM");
        }
    }
}
